package day04;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/11
 */
import java.util.Scanner;
import java.util.Random;

public class GroupGradeAnalyze {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random random = new Random();

        System.out.print("请输入班级总组数:");
        int groupCount = sc.nextInt();
        System.out.print("请输入班级中每组的人数:");
        int stuNumPerGroup = sc.nextInt();

        // 创建二维数组存储成绩
        int[][] grades = new int[groupCount][stuNumPerGroup];

        for (int i = 0; i < groupCount; i++) {
            for (int j = 0; j < stuNumPerGroup; j++) {
                grades[i][j] = random.nextInt(101); // 0-100的随机成绩
            }
        }

        int[] failCount = new int[groupCount]; // 每组不及格人数
        double[] groupAverages = new double[groupCount]; // 每组平均分
        int totalFailCount = 0; // 班级总不及格人数
        double totalScore = 0; // 班级总分
        double maxGroupAverage = 0; // 最高组平均分

        // 统计每组数据
        for (int i = 0; i < groupCount; i++) {
            int groupFailCount = 0;
            double groupTotalScore = 0;

            for (int j = 0; j < stuNumPerGroup; j++) {
                if (grades[i][j] < 60) {
                    groupFailCount++;
                }
                groupTotalScore += grades[i][j];
            }

            // 计算组平均分
            double groupAverage = groupTotalScore / stuNumPerGroup;

            // 更新统计结果
            failCount[i] = groupFailCount;
            groupAverages[i] = groupAverage;
            totalFailCount += groupFailCount;
            totalScore += groupTotalScore;

            // 更新最高组平均分
            if (groupAverage > maxGroupAverage) {
                maxGroupAverage = groupAverage;
            }
        }

        // 计算班级平均分
        double classAverage = totalScore / (groupCount * stuNumPerGroup);

        // 输出结果
        for (int i = 0; i < groupCount; i++) {
            System.out.println("第"+(i + 1)+"组不及格人数为:"+failCount[i]+"人");
            System.out.println("第"+(i + 1)+"组平均分为: "+(int) groupAverages[i]);
        }

        System.out.println("班级中单组最高平均分为:"+(int) maxGroupAverage);
        System.out.println("班级中不及格人数为: "+totalFailCount +"人");
        System.out.println("班级总平均分为: "+(int) classAverage);
    }
}
